package logicaDePredicados;

import java.util.ArrayList;
import java.util.Iterator;

import logicaDePredicados.PredicateLogic;

public class Sentence {
	private ArrayList<PredicateLogic> sentence = new ArrayList<PredicateLogic>();
	public Sentence (){
		
	}
	/**
	 * add an element to the sentence
	 * @param element
	 */
	public void add (PredicateLogic element){
		sentence.add(element);
		
	}
	/**
	 * add a sentence to a specific position. 
	 * @param index
	 * @param element
	 */
	public void add (int index, PredicateLogic element){
		sentence.add(index,element);
	}
	/**
	 * remove an element from it's position. Shift the remaining elements to the left
	 * @param indexOf
	 */
	public void remove (int indexOf){
		sentence.remove(indexOf);
	}
	public String toString (){
		String returnString="";
		Iterator<PredicateLogic> iterator = sentence.iterator();
		while (iterator.hasNext()){
			PredicateLogic term = iterator.next();
			if (term.getClass().equals(LogicPredicate.class)){
				returnString+=term.getName()+"("+iterator.next().getName()+")";
			}else {
				returnString+=term.getName();
			}
		}
		return returnString;
		
	}
	/**
	 * Get actual implementation of the sentence
	 * @return
	 */
	public ArrayList<PredicateLogic> getSentence (){
		return sentence;
	}
	public int size(){
		return sentence.size();
	}
	public int indexOf(PredicateLogic element) {
		return sentence.indexOf(element);
	}
	public PredicateLogic get (int index){
		return sentence.get(index);
	}
	public String rawFormat (){
		System.out.println("raw format sentence");
		String str="";
		for (PredicateLogic i : sentence) {
			str+=i.getName();
		}
		return str;
	}


}
